package org.ntu.csn.as.tool;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.ntu.csn.as.manager.DBManager;
import org.ntu.csn.as.model.Category;
import org.ntu.csn.as.model.SysMessage;
import org.ntu.csn.as.model.Userinfo;

public class WebTool {

	public static void checkUserLogin(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(false);
		Userinfo userinfo = (Userinfo) session.getAttribute("userinfo");
		if (session == null || userinfo == null) {
			SysMessage message = new SysMessage();
			message.setType(Constant.MESSAGE_ERROR);
			message.setMessage("Please login first !");
			request.setAttribute("errorMsg", message);
			request.getRequestDispatcher("login.jsp")
					.forward(request, response);
			
			

		} else {

			return;
		}
	}




}
